package com.lzx.iteam;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.lzx.iteam.net.AsynHttpClient;
import com.lzx.iteam.util.AllDialogUtil;

/**
 * Created by Megan on 16/5/6.
 */
public class HorHelpActivity extends Activity implements View.OnClickListener {

    private LinearLayout mBack;
    private TextView mTvTitle;
    private WebView mWebView;
    private AllDialogUtil mDialogUtil;
    private Dialog mDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.help_layout);
        initView();
        initDatas();
    }

    public void initView() {
        mBack = (LinearLayout) findViewById(R.id.help_ll_back);
        mTvTitle = (TextView) findViewById(R.id.tv_help_name);
        mBack.setOnClickListener(this);
        mWebView = (WebView) findViewById(R.id.help_web_view);
        // 设置webView支持js
        WebSettings ws = mWebView.getSettings();
        ws.setJavaScriptEnabled(true);
        mDialogUtil = AllDialogUtil.getInstance(this);
        mDialog = mDialogUtil.waitDialog();
        mDialog.show();
        mWebView.setWebChromeClient(new WebChromeClient() {

            @Override
            public void onProgressChanged(WebView view, int newProgress) {

                if (newProgress == 100) {
                    mDialog.dismiss();
                }
                super.onProgressChanged(view, newProgress);
            }
        });
    }

    private void initDatas() {
        mTvTitle.setText("计薪说明");
        mWebView.loadUrl(AsynHttpClient.HTTP_HELP_APP_ATTENDANCE);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.help_ll_back:
                finish();
                break;
        }
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
            mWebView.goBack();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}
